home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / Coldfusion / coldfusion-60-win-en.exe / bg.gif < prev    next >
Encoding:
Text File  |  1999-10-22  |  7.5 KB  |  208 lines

  1. trace var="form" category="Form" text="Form Data Passed" inline=true>
  2.     
  3.     <!--- We set a variable called formOK to true. If it becomes false, we know that _something_ went wrong --->
  4.     <cfset formOK = true>
  5.     <!--- This string will contain all the error messages --->
  6.     <cfset errorMsg = "">
  7.     
  8.     <!--- Must have first name, and can't contain funky stuff. Can only have a-z + "'" + spaces --->
  9.     <cfif not len(trim(form.firstName)) or REFindNoCase("[^a-z' ]",form.firstName)>
  10.         <cfset errorMsg = errorMsg & "You must include your first name. It can only contain the characters a-z, apostrophe, and spaces.<br>">
  11.         <cfset formOK = false>
  12.     </cfif>
  13.     <cftrace var="formOK" category="Form Checking" text="After checking First Name" inline=true>
  14.  
  15.     <!--- Must have last name, and can't contain funky stuff. Can only have a-z + "'" + spaces --->
  16.     <cfif not len(trim(form.lastName)) or REFindNoCase("[^a-z' ]",form.lastName)>
  17.         <cfset errorMsg = errorMsg & "You must include your last name. It can only contain the characters a-z, apostrophe, and spaces.<br>">
  18.         <cfset formOK = false>
  19.     </cfif>
  20.     <cftrace var="formOK" category="Form Checking" text="After checking Last Name" inline=true>
  21.  
  22.     <!--- Must have an age, and must be integer, > 0, lt 130  --->
  23.     <cfif not len(trim(form.age)) or not isNumeric(form.age) or form.age is not round(form.age) or form.age lte 0 or form.age gte 130>
  24.         <cfset errorMsg = errorMsg & "You must include your age. It must be a whole number (no decimals allowed).<br>">
  25.         <cfset formOK = false>
  26.     </cfif>
  27.     <cftrace var="formOK" category="Form Checking" text="After checking Age" inline=true>
  28.  
  29.     <!--- Must pick at least one favorite film --->
  30.     <cfif not len(trim(form.favoriteFilms))>
  31.         <cfset errorMsg = errorMsg & "You must pick at least one favorite film.<br>">
  32.         <cfset formOK = false>
  33.     </cfif>
  34.     <cftrace var="formOK" category="Form Checking" text="After checking Favorite Film" inline=true>
  35.     
  36.     <cfif formOK>
  37.     
  38.         <!--- Do something here, save it, whatever. --->
  39.         <cfoutput>
  40.         <p>
  41.         Thank you for filling out the form, #form.firstName# #form.lastName#. You may return to the <a href="index.cfm">original form</a> and try again.
  42.         </p>
  43.         </cfoutput>
  44.  
  45.     </cfif>
  46.     
  47. </cfif>
  48.  
  49.  
  50. <!--- Only display form if you need to --->
  51. <cfif not isDefined("formOK") or not formOK>
  52.  
  53.     <p>
  54.     Please complete the form below. All fields are required. (<i>Although to make the CFTRACE information
  55.     more interesting, you may want to purposely enter incorrect data!</i>)
  56.     </p>
  57.  
  58.     <cfif isDefined("formOK")>
  59.         <p>
  60.         <cfoutput><font color="red">Please correct the following problems:<br>#errorMsg#</font></cfoutput>
  61.         </p>
  62.     </cfif>
  63.     
  64.     <cfoutput>
  65.     <form action="index.cfm" method="post">
  66.     <table cellpadding=5>
  67.         <tr>
  68.             <td>First Name:</td>
  69.             <td><input type="text" name="firstName" value="#form.firstName#"></td>
  70.         </tr>
  71.         <tr>
  72.             <td>Last Name:</td>
  73.             <td><input type="text" name="lastName" value="#form.lastName#"></td>
  74.         </tr>
  75.         <tr>
  76.             <td>Age:</td>
  77.             <td><input type="text" name="age" value="#form.age#"></td>
  78.         </tr>
  79.         <tr valign="top">
  80.             <td>Favorite Movies:</td>
  81.             <td>
  82.                 <table width="100%" cellpadding=0 cellspacing=0>
  83.                     <tr valign="top">
  84.                         <td><input type="checkbox" name="favoriteFilms" value="godfather" <cfif listFind(form.favoriteFilms,"godfather")>checked</cfif>>Godfather  </td>
  85.                         <td><input type="checkbox" name="favoriteFilms" value="starwars" <cfif listFind(form.favoriteFilms,"starwars")>checked</cfif>>Star Wars</td>
  86.                     </tr>
  87.                     <tr valign="top">
  88.                         <td><input type="checkbox" name="favoriteFilms" value="moulinrouge" <cfif listFind(form.favoriteFilms,"moulinrouge")>checked</cfif>>Moulin Rouge  </td>
  89.                         <td><input type="checkbox" name="favoriteFilms" value="unbreakable" <cfif listFind(form.favoriteFilms,"unbreakable")>checked</cfif>>Unbreakable</td>
  90.                     </tr>
  91.                     <tr valign="top">
  92.                         <td><input type="checkbox" name="favoriteFilms" value="matrix" <cfif listFind(form.favoriteFilms,"matrix")>checked</cfif>>The Matrix  </td>
  93.                         <td><input type="checkbox" name="favoriteFilms" value="citizenkane" <cfif listFind(form.favoriteFilms,"citizenkane")>checked</cfif>>Citizen Kane</td>
  94.                     </tr>
  95.                     <tr valign="top">
  96.                         <td><input type="checkbox" name="favoriteFilms" value="conversation" <cfif listFind(form.favoriteFilms,"conversation")>checked</cfif>>The Conversation  </td>
  97.                         <td><input type="checkbox" name="favoriteFilms" value="heat" <cfif listFind(form.favoriteFilms,"heat")>checked</cfif>>Heat</td>
  98.                     </tr>                
  99.                 </table>
  100.             </td>
  101.         </tr>
  102.         <tr>
  103.             <td> </td>
  104.             <td><input type="submit" name="submit" value="Send Data"></td>
  105.         </tr>
  106.     </table>
  107.     </form>
  108.     </cfoutput>
  109.  
  110. </cfif>
  111.  
  112. </cfmodule>
  113. <!--- 
  114. **
  115. * CFMX Example Applications
  116. *
  117. * Copyright (c) 2002 Macromedia.  All Rights Reserved.
  118. *
  119. * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
  120. * TERMS AND CONDITIONS SET FORTH IN THE CORRESPONDING EULA.
  121. *
  122. **
  123.  --->
  124.  
  125. <cfmodule template="../tags/layout.cfm" pageName="CFTRACE Example - Page Source">
  126.  
  127.     <cfset variables.files = "index.cfm">
  128.  
  129.     <cfinclude template="../tags/showsource.cfm">
  130.  
  131. </cfmodule>
  132. <!--- 
  133. **
  134. * CFMX Example Applications
  135. *
  136. * Copyright (c) 2002 Macromedia.  All Rights Reserved.
  137. *
  138. * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
  139. * TERMS AND CONDITIONS SET FORTH IN THE CORRESPONDING EULA.
  140. *
  141. **
  142.  --->
  143.  
  144. <cfmodule template="../tags/bts_layout.cfm" exampleName="Data Drill-Down Example"
  145.     source="index.cfm,results.cfm,detail.cfm"
  146.     keyTags="cfquery@Tags78.html,cfset@Tags94.html,cfif cfelse cfelseif@Tags49.html,IsDefined()@Functions122.html">
  147.  
  148.     <p>
  149.     The Store Catalog example takes the basic search presented in the Personnel Directory one step further by displaying multiple matches to the initial search and allowing the user to "drill-down" to find more detail about each match. Notice information being passed from page to page in two different ways; via a form post and via a URL parameter. 
  150.     </p>
  151.     
  152.     <p>
  153.     The example also demonstrates how to implement a "Prior/Next" link to allow a user to view a large set of results over multiple pages.
  154.     </p>
  155.  
  156. </cfmodule>
  157.  
  158. <!--- 
  159. **
  160. * CFMX Example Applications
  161. *
  162. * Copyright (c) 2002 Macromedia.  All Rights Reserved.
  163. *
  164. * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
  165. * TERMS AND CONDITIONS SET FORTH IN THE CORRESPONDING EULA.
  166. *
  167. **
  168.  --->
  169.  
  170. <cfmodule template="../tags/layout.cfm" pageName="Data Drill-Down Example">
  171.  
  172. <!---
  173.     Now that we have a single item, we can select just that
  174.     one record and display the full details.
  175. --->
  176.  
  177. <!--- Check for url.ItemID --->
  178. <cfif not isDefined("url.itemID")>
  179.     <!--- Send them away if not! --->
  180.     <cflocation url="index.cfm">
  181. </cfif>
  182.  
  183. <!--- request.app.dsn is a variable set in the root
  184.       Application.cfm file. By setting the datasource name
  185.       as a variable, it makes it very easy to change DSN names
  186.       later on. --->
  187. <cfquery name="TheItem" dataSource="#request.app.dsn#">
  188. select    tblCategories.CategoryName, 
  189.         tblItems.*
  190. from    tblCategories, tblItems
  191. where    tblCategories.CategoryID = tblItems.CategoryIDFK
  192. and        tblItems.ItemID = '#url.itemID#'
  193. </cfquery>
  194.  
  195. <!--- 
  196.     If the record didn't exist, send the user away 
  197.     "not TheItem.recordCount" will be true if the recordcount
  198.     is 0. Not 0 is 1.
  199. --->
  200. <cfif not TheItem.recordCount>
  201.     <cflocation url="index.cfm">
  202. </cfif>
  203.  
  204. <p>
  205. By passing the item's ID as a URL parameter (notice the URL in your
  206. browser shows this page as detail.cfm?ItemID=XXXXXXX, where X is a long
  207. ID string), you can query the database for complete information about
  208. this ite